<template>
<!--  lbj-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="负责老师" prop="teachername">
        <el-select v-model="queryParams.teachername" placeholder="请选择跟踪老师">
          <el-option
            v-for="dict in teachList"
            :label="dict.name"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select v-model="queryParams.classId" placeholder="请选择班级" clearable
                   @keyup.enter.native="handleQuery">
          <el-option
            v-for="dict in classList"
            :label="dict.name"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学生" prop="studentId">
        <el-select v-model="queryParams.studentId" placeholder="请选择学生" clearable
                   @keyup.enter.native="handleQuery">
          <el-option
            v-for="dict in stuList"
            :label="dict.name"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学生状态" prop="stuType">
        <el-select v-model="queryParams.stuType" placeholder="请选择学生状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_student_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="困难系数" prop="difficulty">
        <el-select v-model="queryParams.difficulty" placeholder="请选择困难系数" clearable>
          <el-option
            v-for="dict in dict.type.sys_difficulty_coefficient"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="模拟面试" prop="interview">
        <el-select v-model="queryParams.interview" placeholder="请选择模拟面试" clearable>
          <el-option
            v-for="dict in dict.type.sys_interview"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="考试" prop="exam">
        <el-select v-model="queryParams.exam" placeholder="请选择考试" clearable >
          <el-option
            v-for="dict in dict.type.sys_end_test"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teaching:focuson:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teaching:focuson:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teaching:focuson:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teaching:focuson:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="focusonList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="index" prop="id" />
      <el-table-column label="负责老师名字" align="center" prop="teaches.name" />
      <el-table-column label="所属班级" align="center" prop="bblClass.name" />
      <el-table-column label="学生姓名" align="center" prop="students.name" />
      <el-table-column label="学生状态" align="center" prop="stuType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_student_type" :value="scope.row.stuType"/>
        </template>
      </el-table-column>
      <el-table-column label="困难系数" align="center" prop="difficulty">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_difficulty_coefficient" :value="scope.row.difficulty"/>
        </template>
      </el-table-column>
      <el-table-column label="模拟面试" align="center" prop="interview">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_interview" :value="scope.row.interview"/>
        </template>
      </el-table-column>
      <el-table-column label="考试" align="center" prop="exam">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_end_test" :value="scope.row.exam"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teaching:focuson:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teaching:focuson:remove']"
          >不再关注</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="handLetrackRecord(scope.row)"
            v-hasPermi="['teaching:focuson:remove']"
          >跟踪记录</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改重点关注对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="负责老师" prop="teachername">
          <el-select v-model="form.teacherId" placeholder="请选择跟踪老师">
            <el-option
              v-for="dict in teachList"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属班级" prop="classes">
          <el-select v-model="form.classId" placeholder="请选择班级">
            <el-option
              v-for="dict in classList"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生" prop="studentsname">
          <el-select v-model="form.studentId" placeholder="请选择学生">
            <el-option
              v-for="dict in stuList"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生状态" prop="stuType">
          <el-select v-model="form.stuType" placeholder="请选择学生状态">
            <el-option
              v-for="dict in dict.type.sys_student_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="困难系数" prop="difficulty">
          <el-select v-model="form.difficulty" placeholder="请选择困难系数">
            <el-option
              v-for="dict in dict.type.sys_difficulty_coefficient"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模拟面试" prop="interview">
          <el-select v-model="form.interview" placeholder="请选择模拟面试">
            <el-option
              v-for="dict in dict.type.sys_interview"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考试" prop="exam">
          <el-select v-model="form.exam" placeholder="请选择考试">
            <el-option
              v-for="dict in dict.type.sys_end_test"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 跟踪记录 -->
    <el-dialog :title="title" :visible.sync="stalkeFormVisible">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in teachStalke"
          :key="index"
          :color="colors(index)"
          type="primary"
          :timestamp="activity.creationtime"
          placement="top">
          <el-card>
              <h1>跟踪人：{{activity.teachername}}</h1>
              <h3>问题说明：{{activity.remark}} </h3>
          </el-card>
        </el-timeline-item>
      </el-timeline>
      <div slot="footer" class="dialog-footer">
        <el-button @click="stalkeFormVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFocuson, getFocuson, delFocuson, addFocuson, updateFocuson } from "@/api/teaching/focuson";
import {getClass, getfindListByStudentId, getStu, getteacher} from "@/api/teaching/stalke";
export default {
  name: "Focuson",
  dicts: ['sys_end_test', 'sys_student_type', 'sys_difficulty_coefficient', 'sys_interview'],
  data() {
    return {
      // 跟踪记录数据
      teachStalke:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 重点关注表格数据
      focusonList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacher: null,
        classes: null,
        student: null,
        stuType: null,
        difficulty: null,
        interview: null,
        exam: null,
        teacherId: null,
        classId: null,
        studentId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 跟踪弹框是否弹出
      stalkeFormVisible:false,


      // 所有学生
      stuList:[],
      // 所有老师
      teachList:[],
      // 所有班级
      classList:[],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询重点关注列表 */
    getList() {
      this.loading = true;
      listFocuson(this.queryParams).then(response => {
        this.focusonList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        teacher: null,
        classes: null,
        student: null,
        stuType: null,
        difficulty: null,
        interview: null,
        exam: null,
        teacherId: null,
        classId: null,
        studentId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加重点关注";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFocuson(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改重点关注";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFocuson(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFocuson(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除重点关注编号为"' + ids + '"的数据项？').then(function() {
        return delFocuson(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('teaching/focuson/export', {
        ...this.queryParams
      }, `focuson_${new Date().getTime()}.xlsx`)
    },
    /** 跟踪记录*/
    handLetrackRecord(row){
      let name = row.student
      this.stalkeFormVisible=true;
      this.title = "【"+name+"】的跟踪历史"
      getfindListByStudentId(row.studentId).then(res => {
        this.teachStalke = res.data
        console.log(JSON.stringify(res.data))
      })
    },
    /** 获得学生的全部*/
    getstuList(){
      getStu().then(response =>{
        this.stuList = response.rows
      })
    },
    /** 获得老师的全部*/
    getTeacherList(){
      getteacher().then(response =>{
        this.teachList = response.rows
      })
    },
    /** 获得班级的全部*/
    getclassList(){
      getClass().then(response =>{
        this.classList = response.rows
      })
    },
    /**根据下标选颜色*/
    colors(index){
      if (index % 2 == 0){
        return '00D6FDFF'
      } else {
        return 'D81E1EFF'
      }
    }
  },
  mounted() {
    this.getstuList();
    this.getclassList();
    this.getTeacherList();
  }
};
</script>
